<template>
  <div id="header">
    <ul class="title">
      <li class="floatLeft">
        <img src="@/assets/icon/logo365.png"/>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
          <el-breadcrumb-item :to="{ path: '/HomeIndex' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item v-for="item in $route.meta" :key="item">{{item}}</el-breadcrumb-item>
        </el-breadcrumb>
      </li>
      <li class="floatRight">
        <el-dropdown @command="handleCommand" menu-align='start'>
          <img :src="imgPath + avatar">
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="home">首页</el-dropdown-item>
            <el-dropdown-item command="singout">退出</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </li>
    </ul>
  </div>
</template>
<script>
  import api from '@/api/center'
  import store from '@/store'

  export default {
    data() {
      return {
        imgPath: '',//头像地址
      }
    },
    computed: {
      avatar:function () {
        return this.$store.state.adminInfo.avatar;
      }
    },
    mounted: function () {
      this.imgPath = this.$store.state.imgPath;
      api.queryAdminInfo().then(res => {
        if (res.status === 1) {
          let params = {
            avatar: res.data.avatar
          };
          store.commit('saveAdminInfo', params);
        } else {
          console.log('您尚未登陆或者session失效');
          this.$message.error('您尚未登陆或者session失效');
        }
      });
    },
    methods: {
      handleCommand(command) {
        if (command == 'home') {
          this.$router.push('/HomeIndex');
        } else if (command == 'singout') {
          api.adminSingOut().then(res => {
            if (res.status == 1) {
              this.$message({
                type: 'success',
                message: '退出成功'
              });
              this.$router.push('/');
            } else {
              this.$message({
                type: 'error',
                message: res.message
              });
            }
          });
        }
      }
    }
  }
</script>
<style lang="stylus" scoped>
  #header {
    position absolute
    top 0
    left 0
    width 100%
    z-index 200
    color #999
    background #fff
  }

  .title {
    width 100%
    height 48px
    line-height 48px
    font-size 16px
    color #666
    margin 0 auto
  }

  .floatLeft {
    position relative
    display inline-block
    height 48px
    img {
      display inline-block
      width 200px
      height 28px
      margin-bottom 10px
      padding 0 10px
    }
    .breadcrumb {
      display inline-block
      line-height 48px
      margin-left 20px
    }
  }

  .floatRight {
    float right
    img {
      width 38px
      height 38px
      margin 5px 40px 0 0
      vertical-align top
      border-radius 50%
    }
  }
</style>
